<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="./style/booksList.css" />
<title>图书列表</title>
</head>
<body>
<?php
include_once '../tools/SqlHelper.class.php';
$sqlHelper = new SqlHelper ();
if (isset ( $_GET ['userid'] )) {
	$userid = $_GET ['userid'];
	$isAdd = true;
	$sql = "DELETE FROM `user_tb` WHERE `user_id`='$userid'";
	$result = $sqlHelper->execute_dql ( $sql );
	if (! $result) {
		$isAdd = false; // 删除失败
	}
	$sql = "DELETE FROM `personal_data_tb` WHERE `user_id`='$userid'";
	$result = $sqlHelper->execute_dql ( $sql );
	if (! $result) {
		$isAdd = false; // 删除失败
	}
	$sql = "DELETE FROM `detail_data_tb` WHERE `user_id`='$userid'";
	$result = $sqlHelper->execute_dql ( $sql );
	if (! $result) {
		$isAdd = false; // 删除失败
	}
	$sql = "DELETE FROM `personals_condition_tb` WHERE `user_id`='$userid'";
	$result = $sqlHelper->execute_dql ( $sql );
	if (! $result) {
		$isAdd = false; // 删除失败
	}
	if ($isAdd) {
		echo "<script>alert('删除成功')</script>";
	} else {
		echo "<script>alert('删除失败')</script>";
	}
}
// 每页的显示条数
$page_size = 9;
// 当前页码
$page_num = 1;
if (is_numeric ( $_GET ['page'] )) {
	$page_num = ( int ) $_GET ['page'];
}
// 总条数
// $resultA = mysql_query ( "select count(bookid) as total from book_info" );
$sql = "select count(user_id) from `user_tb`";
// 创建一个SqlHelper对象
$resultA = $sqlHelper->execute_dql ( $sql );
$row = mysql_fetch_array ( $resultA );
$data_count = $row ['0'];
// 总页数
$page_count = ceil ( $data_count / $page_size );

// 当前页码中的数据
$offset = ($page_num - 1) * $page_size;
$sql = "select * from user_tb where 1=1 order by user_tb_id asc limit $offset , $page_size";
$resultB = $sqlHelper->execute_dql ( $sql );
// $resultB = mysql_query ( "select * from book_info where 1=1 order by _id asc limit $offset , $page_size" );
$row = mysql_fetch_array ( $resultB );
?>
	<form action="./infoList.php" target="frm" method="get">
		<div>
			<h1>会员列表</h1>
			<table class="tb_list">
				<tr>
					<th>会员名</th>
					<th>用户名</th>
					<th>性别</th>
					<th>删除</th>
				</tr>
				<?php
				// 创建页面元素数据
				if (! $row) {
					echo "<tr><td colspan='3'>暂无数据</td></tr>";
				} else {
					do {
						$user_id = $row ['user_id'];
						$sql = "select ps_sex from personal_data_tb where `user_id`='$user_id'";
						$resultB2 = $sqlHelper->execute_dql ( $sql );
						$row2 = mysql_fetch_array ( $resultB2 );
						echo "<tr>";
						echo "<td><a href='afterInfo.php?_id=" . $row ['user_tb_id'] . "'>" . $row ['user_id'] . "</a></td>";
						echo "<td>" . $row ['user_name'] . "</td>";
						if ($row2 ['ps_sex'] == 0) {
							echo "<td>男</td>";
						} else {
							echo "<td>女</td>";
						}
						echo "<td><a href='infoList.php?userid=" . $row ['user_id'] . "'>删除</a></td>";
						echo "</tr>";
					} while ( ! ! ($row = mysql_fetch_array ( $resultB )) );
				}
				?>
			</table>
		</div>
		<div class="table_style_pager">
			<table class="tb_pager">
				<tr>
					<td class="td1"><?php
					if ($page_num > 1) {
						echo "<a href='infoList.php?page=1' target='_self'>首页</a>&nbsp;";
						echo "<a href='infoList.php?page=" . ($page_num - 1) . "' target='_self'>上一页</a>&nbsp;";
					}
					if ($page_num < $page_count) {
						echo "<a href='infoList.php?page=" . ($page_num + 1) . "' target='_self'>下一页</a>&nbsp;";
						echo "<a href='infoList.php?page=" . $page_count . "' target='_self'>尾页</a>&nbsp;";
					}
					?></td>
					<td class="td2">当前页<?php echo $page_num."/".$page_count; ?></td>
					<td class="td2">共<?php echo $data_count; ?>条记录</td>
				</tr>
			</table>
			<h2></h2>
			<div class="table_style_page">
				<label> 跳转到： </label> <input type="text" name="page">页</input> <input
					class="button" name="user_submit" type="submit" value="跳转" />
			</div>
		</div>
	</form>
</body>
</html>
